<?php
namespace Admin\Controller;
use Think\Controller;

class UserController extends Controller {
    
    public function login(){
      	$username = $_POST['username'];
        $password = md5($_POST['password']);
        $m=M("SysUser");
        $result = $m->where("username = '{$username}' AND password = '{$password}'")->find();
        if($result>0){
            $_SESSION['muser']=$result['username'];
            $_SESSION['mnickname']=$result['nickname'];
            $_SESSION['userid']=$result['id'];
            $this->success("登陆成功！");

           // $_SESSION['mlasttime']=$result['lasttime'];
           // $m->where("id = {$result['id']}")->setField('lasttime',time());
           //// $_SESSION['mlastip']=$result['ip'];
           // $m->where("id = {$result['id']}")->setField('ip',$_SERVER["REMOTE_ADDR"]);
        }else{
            $this->error("登陆失败！");
        }
    }

     public function index(){
       $this->display();
     }

     public function page(){
        $page = $_POST['page'];
        $rows = $_POST['rows'];
        $sort = $_POST['sort'];
        $order = $_POST['order'];
        $User = M("SysUser");
        $count = $User->where('isDelete=0')->order('id asc')->count();
        $list = $User->where('isDelete=0')->order('id asc')->limit((($page - 1)*$rows).','.$rows)->select();
        //$list = $User->order('id desc')->select();
        $data = array(
                'rows' => $list,
                'total' => $count
        );
        if($data>0){
            $this->ajaxReturn($data);
        }
    }

    public function add(){
     
    }

    public function update(){
     
    }
    //   /** 结果 0表示失败 1表示成功 */
    // private int result;

    // /** 提示信息 */
    // private String msg = "";

    // /** 附加对象，用来存储一些特定的返回信息 */
    // private Object obj;
    public function delete($ids){
      $User = M("SysUser");
      $data['isDelete'] = '1';
      $User->where("id in('{$ids}')")->save($data);
      $ajaxdata = array(
                'result' => 1,
                'msg' => '删除成功'
      );
      $this->ajaxReturn($ajaxdata);
    }
    
}